package com.example.j202411.views.Activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;
import com.example.j202411.databinding.ActivityPetDetailBinding;
import com.example.j202411.Model.PetEntity;


public class PetsDetailsActivity extends AppCompatActivity {

    private PetEntity.Result.ListDate data;
    private ActivityPetDetailBinding binding;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityPetDetailBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        init();
    }

    private void init() {
        // 获取传入的宠物对象
        data = (PetEntity.Result.ListDate) getIntent().getSerializableExtra("data");
        Log.d("getIntent()11111111111", String.valueOf(data));
        if (data != null) {
            // 绑定数据到视图
            binding.name.setText("姓名：\n" + data.getName());
            binding.engName.setText("英文名：\n" + data.getEngName());
            binding.characters.setText("性格：\n" + data.getCharacters());
            binding.nation.setText("祖籍：\n" + data.getNation());
            binding.easyOfDisease.setText("易患病：\n" + data.getEasyOfDisease());
            binding.life.setText("寿命：\n" + data.getLife());
            binding.desc.setText("介绍：\n" + data.getDesc());
            binding.feature.setText("特点：\n" + data.getFeature());
            binding.characterFeature.setText("角色特征：\n" + data.getCharacterFeature());
            binding.careKnowledge.setText("护理知识：\n" + data.getCareKnowledge());
            binding.feedPoints.setText("进食特点：\n" + data.getFeedPoints());

            // 加载封面图片
            Glide.with(this)
                    .load(data.getCoverURL())
                    .into(binding.coverImage);

            // 设置封面图片点击事件
            binding.coverImage.setOnClickListener(v -> {
                Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(data.getUrl()));
                startActivity(browserIntent);
            });
        }
    }
}